package com.wondersgroup.fjzlpt.yyzyzx.service.impl.yyzycx;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.quick.framework.util.ExcelOrWordUtils;
import com.wondersgroup.fjzlpt.yyzyzx.dao.inter.yyzycx.HyxxDAO;
import com.wondersgroup.fjzlpt.yyzyzx.service.inter.yyzycx.HyxxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 号源信息查询实现层
 * <p>
 * <p>
 * Created by sanma on 2017/8/7.
 */
@Service
public class HyxxServiceImpl implements HyxxService{

    @Autowired
    private HyxxDAO hyxxDAO;

    @Override
    public JSONObject pageQueryHyxxAll(Map map) {
        return hyxxDAO.pageQueryHyxxAll(map);
    }

    /**
     * 查询所有数据
     * @param map
     * @return
     */
    @Override
    public void queryAllForExcel(Map map, HttpServletRequest request, HttpServletResponse response) {
        JSONArray downData = hyxxDAO.queryAll(map);

        //表头
        StringBuffer titleStr = new StringBuffer();
        titleStr.append("{'YLJGMC':'医疗机构名称','YJKSMC':'一级科室','YSXM':'医生姓名','ZYLXMC':'资源类型','HYLXMC':'号源类型','PBRQ':'排版日期',")
                .append("'YYSD':'时段','YYSJD':'时间段','YYZHYS':'医院总号源数','SYHYS':'剩余号源数','YYYS':'已预约数','HYZT':'号源状态'}");
        JSONObject title = JSONObject.parseObject(titleStr.toString());
        downData.add(0, title);

        //排列循序
        List<String> titelField = new ArrayList<>();
        titelField.add("YLJGMC");
        titelField.add("YJKSMC");
        titelField.add("YSXM");
        titelField.add("ZYLXMC");
        titelField.add("HYLXMC");
        titelField.add("PBRQ");
        titelField.add("YYSD");
        titelField.add("YYSJD");
        titelField.add("YYZHYS");
        titelField.add("SYHYS");
        titelField.add("YYYS");
        titelField.add("HYZT");
        ExcelOrWordUtils.downLoadExcelFile(downData, titelField ,"号源信息列表",request, response);

    }
}
